home *** CD-ROM | disk | FTP | other *** search
/ Champak 143 / (Vol 143) Nov 15 2011.iso / Games / bratz_getting_ready.swf / scripts / FScrollBarSymbol.as next >
Text File  |  2011-11-15  |  12KB  |  371 lines

  1. FScrollBarClass = function()
  2. {
  3.    if(this._height == 4)
  4.    {
  5.       return undefined;
  6.    }
  7.    this.init();
  8.    this.minPos = this.maxPos = this.pageSize = this.largeScroll = 0;
  9.    this.smallScroll = 1;
  10.    this._yscale = 190;
  11.    this.width = !this.horizontal ? this._height : this._width;
  12.    this._xscale = this._yscale = 100;
  13.    this.setScrollPosition(0);
  14.    this.tabEnabled = false;
  15.    if(this._targetInstanceName.length > 0)
  16.    {
  17.       this.setScrollTarget(this._parent[this._targetInstanceName]);
  18.    }
  19.    this.tabChildren = false;
  20.    this.setSize(this.width);
  21. };
  22. FScrollBarClass.prototype = new FUIComponentClass();
  23. FScrollBarClass.prototype.setHorizontal = function(flag)
  24. {
  25.    if(this.horizontal && !flag)
  26.    {
  27.       this._xscale = 100;
  28.       this._rotation = 0;
  29.    }
  30.    else if(flag && !this.horizontal)
  31.    {
  32.       this._xscale = -100;
  33.       this._rotation = -90;
  34.    }
  35.    this.horizontal = flag;
  36. };
  37. FScrollBarClass.prototype.setScrollProperties = function(pSize, mnPos, mxPos)
  38. {
  39.    if(!this.enable)
  40.    {
  41.       return undefined;
  42.    }
  43.    this.pageSize = pSize;
  44.    trace("max:" + mxPos);
  45.    this.minPos = Math.max(mnPos,0);
  46.    this.maxPos = Math.max(mxPos,0);
  47.    this.scrollPosition = Math.max(this.minPos,this.scrollPosition);
  48.    this.scrollPosition = Math.min(this.maxPos,this.scrollPosition);
  49.    if(this.maxPos - this.minPos <= 0)
  50.    {
  51.       this.scrollThumb_mc.removeMovieClip();
  52.       this.upArrow_mc.gotoAndStop(3);
  53.       this.downArrow_mc.gotoAndStop(3);
  54.       this.downArrow_mc.onPress = this.downArrow_mc.onRelease = this.downArrow_mc.onDragOut = null;
  55.       this.upArrow_mc.onPress = this.upArrow_mc.onRelease = this.upArrow_mc.onDragOut = null;
  56.       this.scrollTrack_mc.onPress = this.scrollTrack_mc.onRelease = null;
  57.       this.scrollTrack_mc.onDragOut = this.scrollTrack_mc.onRollOut = null;
  58.       this.scrollTrack_mc.useHandCursor = false;
  59.    }
  60.    else
  61.    {
  62.       trace(this.scrollThumb_mc);
  63.       var _loc2_ = this.getScrollPosition();
  64.       this.upArrow_mc.gotoAndStop(1);
  65.       this.downArrow_mc.gotoAndStop(1);
  66.       this.upArrow_mc.onPress = this.upArrow_mc.onDragOver = this.startUpScroller;
  67.       this.upArrow_mc.onRelease = this.upArrow_mc.onDragOut = this.stopScrolling;
  68.       this.downArrow_mc.onPress = this.downArrow_mc.onDragOver = this.startDownScroller;
  69.       this.downArrow_mc.onRelease = this.downArrow_mc.onDragOut = this.stopScrolling;
  70.       this.scrollTrack_mc.onPress = this.scrollTrack_mc.onDragOver = this.startTrackScroller;
  71.       this.scrollTrack_mc.onRelease = this.stopScrolling;
  72.       this.scrollTrack_mc.onDragOut = this.stopScrolling;
  73.       this.scrollTrack_mc.onRollOut = this.stopScrolling;
  74.       this.scrollTrack_mc.useHandCursor = false;
  75.       this.attachMovie("ScrollThumb","scrollThumb_mc",3);
  76.       this.scrollThumb_mc._x = 0;
  77.       this.scrollThumb_mc._y = this.upArrow_mc._height;
  78.       this.scrollThumb_mc.onPress = this.startDragThumb;
  79.       this.scrollThumb_mc.controller = this;
  80.       this.scrollThumb_mc.onRelease = this.scrollThumb_mc.onReleaseOutside = this.stopDragThumb;
  81.       this.scrollThumb_mc.useHandCursor = false;
  82.       this.thumbHeight = this.pageSize / (this.maxPos - this.minPos + this.pageSize) * this.trackSize;
  83.       this.thumbMid_mc = this.scrollThumb_mc.mc_sliderMid;
  84.       this.thumbTop_mc = this.scrollThumb_mc.mc_sliderTop;
  85.       this.thumbBot_mc = this.scrollThumb_mc.mc_sliderBot;
  86.       this.thumbHeight = Math.max(this.thumbHeight,6);
  87.       this.midHeight = this.thumbHeight - this.thumbTop_mc._height - this.thumbBot_mc._height;
  88.       this.thumbMid_mc._yScale = this.midHeight * 100 / this.thumbMid_mc._height;
  89.       this.thumbMid_mc._y = this.thumbTop_mc._height;
  90.       this.thumbBot_mc._y = this.thumbTop_mc._height + this.midHeight;
  91.       this.scrollTop = this.scrollThumb_mc._y;
  92.       this.trackHeight = this.trackSize - this.thumbHeight;
  93.       this.scrollBot = this.trackHeight + this.scrollTop;
  94.       _loc2_ = Math.min(_loc2_,this.maxPos);
  95.       this.setScrollPosition(Math.max(_loc2_,this.minPos));
  96.    }
  97. };
  98. FScrollBarClass.prototype.getScrollPosition = function()
  99. {
  100.    return this.scrollPosition;
  101. };
  102. FScrollBarClass.prototype.setScrollPosition = function(pos)
  103. {
  104.    this.scrollPosition = pos;
  105.    if(this.scrollThumb_mc != undefined)
  106.    {
  107.       pos = Math.min(pos,this.maxPos);
  108.       pos = Math.max(pos,this.minPos);
  109.    }
  110.    this.scrollThumb_mc._y = (pos - this.minPos) * this.trackHeight / (this.maxPos - this.minPos) + this.scrollTop;
  111.    this.executeCallBack();
  112. };
  113. FScrollBarClass.prototype.setLargeScroll = function(lScroll)
  114. {
  115.    this.largeScroll = lScroll;
  116. };
  117. FScrollBarClass.prototype.setSmallScroll = function(sScroll)
  118. {
  119.    this.smallScroll = sScroll;
  120. };
  121. FScrollBarClass.prototype.setEnabled = function(enabledFlag)
  122. {
  123.    var _loc3_ = this.enable;
  124.    if(enabledFlag && !_loc3_)
  125.    {
  126.       this.enable = enabledFlag;
  127.       if(this.textField != undefined)
  128.       {
  129.          this.setScrollTarget(this.textField);
  130.       }
  131.       else
  132.       {
  133.          this.setScrollProperties(this.pageSize,this.cachedMinPos,this.cachedMaxPos);
  134.          this.setScrollPosition(this.cachedPos);
  135.       }
  136.       this.clickFilter = undefined;
  137.    }
  138.    else if(!enabledFlag && _loc3_)
  139.    {
  140.       this.textField.removeListener(this);
  141.       this.cachedPos = this.getScrollPosition();
  142.       this.cachedMinPos = this.minPos;
  143.       this.cachedMaxPos = this.maxPos;
  144.       if(this.clickFilter == undefined)
  145.       {
  146.          this.setScrollProperties(this.pageSize,0,0);
  147.       }
  148.       else
  149.       {
  150.          this.clickFilter = true;
  151.       }
  152.       this.enable = enabledFlag;
  153.    }
  154. };
  155. FScrollBarClass.prototype.setSize = function(hgt)
  156. {
  157.    if(this._height == 1)
  158.    {
  159.       return undefined;
  160.    }
  161.    this.width = hgt;
  162.    this.scrollTrack_mc._yscale = 100;
  163.    this.scrollTrack_mc._yscale = 100 * this.width / this.scrollTrack_mc._height;
  164.    if(this.upArrow_mc == undefined)
  165.    {
  166.       this.attachMovie("UpArrow","upArrow_mc",1);
  167.       this.attachMovie("DownArrow","downArrow_mc",2);
  168.       this.downArrow_mc.controller = this.upArrow_mc.controller = this;
  169.       this.upArrow_mc.useHandCursor = this.downArrow_mc.useHandCursor = false;
  170.       this.upArrow_mc._x = this.upArrow_mc._y = 0;
  171.       this.downArrow_mc._x = 0;
  172.    }
  173.    this.scrollTrack_mc.controller = this;
  174.    this.downArrow_mc._y = this.width - this.downArrow_mc._height;
  175.    this.trackSize = this.width - 2 * this.downArrow_mc._height;
  176.    if(this.textField != undefined)
  177.    {
  178.       this.onTextChanged();
  179.    }
  180.    else
  181.    {
  182.       this.setScrollProperties(this.pageSize,this.minPos,this.maxPos);
  183.    }
  184. };
  185. FScrollBarClass.prototype.scrollIt = function(inc, mode)
  186. {
  187.    var _loc3_ = this.smallScroll;
  188.    if(inc != "one")
  189.    {
  190.       _loc3_ = this.largeScroll != 0 ? this.largeScroll : this.pageSize;
  191.    }
  192.    var _loc2_ = this.getScrollPosition() + mode * _loc3_;
  193.    if(_loc2_ > this.maxPos)
  194.    {
  195.       _loc2_ = this.maxPos;
  196.    }
  197.    else if(_loc2_ < this.minPos)
  198.    {
  199.       _loc2_ = this.minPos;
  200.    }
  201.    this.setScrollPosition(_loc2_);
  202. };
  203. FScrollBarClass.prototype.startDragThumb = function()
  204. {
  205.    this.lastY = this._ymouse;
  206.    this.onMouseMove = this.controller.dragThumb;
  207. };
  208. FScrollBarClass.prototype.dragThumb = function()
  209. {
  210.    this.scrollMove = this._ymouse - this.lastY;
  211.    this.scrollMove += this._y;
  212.    if(this.scrollMove < this.controller.scrollTop)
  213.    {
  214.       this.scrollMove = this.controller.scrollTop;
  215.    }
  216.    else if(this.scrollMove > this.controller.scrollBot)
  217.    {
  218.       this.scrollMove = this.controller.scrollBot;
  219.    }
  220.    this._y = this.scrollMove;
  221.    var _loc2_ = this.controller;
  222.    _loc2_.scrollPosition = Math.round((_loc2_.maxPos - _loc2_.minPos) * (this._y - _loc2_.scrollTop) / _loc2_.trackHeight) + _loc2_.minPos;
  223.    this.controller.isScrolling = true;
  224.    updateAfterEvent();
  225.    this.controller.executeCallBack();
  226. };
  227. FScrollBarClass.prototype.stopDragThumb = function()
  228. {
  229.    this.controller.isScrolling = false;
  230.    this.onMouseMove = null;
  231. };
  232. FScrollBarClass.prototype.startTrackScroller = function()
  233. {
  234.    this.controller.trackScroller();
  235.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"page",-1);
  236. };
  237. FScrollBarClass.prototype.scrollInterval = function(inc, mode)
  238. {
  239.    clearInterval(this.scrolling);
  240.    if(inc == "page")
  241.    {
  242.       this.trackScroller();
  243.    }
  244.    else
  245.    {
  246.       this.scrollIt(inc,mode);
  247.    }
  248.    this.scrolling = setInterval(this,"scrollInterval",35,inc,mode);
  249. };
  250. FScrollBarClass.prototype.trackScroller = function()
  251. {
  252.    if(this.scrollThumb_mc._y + this.thumbHeight < this._ymouse)
  253.    {
  254.       this.scrollIt("page",1);
  255.    }
  256.    else if(this.scrollThumb_mc._y > this._ymouse)
  257.    {
  258.       this.scrollIt("page",-1);
  259.    }
  260. };
  261. FScrollBarClass.prototype.stopScrolling = function()
  262. {
  263.    this.controller.downArrow_mc.gotoAndStop(1);
  264.    this.controller.upArrow_mc.gotoAndStop(1);
  265.    clearInterval(this.controller.scrolling);
  266. };
  267. FScrollBarClass.prototype.startUpScroller = function()
  268. {
  269.    this.controller.upArrow_mc.gotoAndStop(2);
  270.    this.controller.scrollIt("one",-1);
  271.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"one",-1);
  272. };
  273. FScrollBarClass.prototype.startDownScroller = function()
  274. {
  275.    this.controller.downArrow_mc.gotoAndStop(2);
  276.    this.controller.scrollIt("one",1);
  277.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"one",1);
  278. };
  279. FScrollBarClass.prototype.setScrollTarget = function(tF)
  280. {
  281.    if(tF == undefined)
  282.    {
  283.       this.textField.removeListener(this);
  284.       delete this.textField[!this.horizontal ? "vScroller" : "hScroller"];
  285.       if(this.textField.hScroller != undefined && this.textField.vScroller != undefined)
  286.       {
  287.          this.textField.unwatch("text");
  288.          this.textField.unwatch("htmltext");
  289.       }
  290.    }
  291.    this.textField = undefined;
  292.    if(!(tF instanceof TextField))
  293.    {
  294.       return undefined;
  295.    }
  296.    this.textField = tF;
  297.    this.textField[!this.horizontal ? "vScroller" : "hScroller"] = this;
  298.    this.onTextChanged();
  299.    this.onChanged = function()
  300.    {
  301.       this.onTextChanged();
  302.    };
  303.    this.onScroller = function()
  304.    {
  305.       if(!this.isScrolling)
  306.       {
  307.          if(!this.horizontal)
  308.          {
  309.             this.setScrollPosition(this.textField.scroll);
  310.          }
  311.          else
  312.          {
  313.             this.setScrollPosition(this.textField.hscroll);
  314.          }
  315.       }
  316.    };
  317.    this.textField.addListener(this);
  318.    this.textField.watch("text",this.callback);
  319.    this.textField.watch("htmlText",this.callback);
  320. };
  321. FScrollBarClass.prototype.callback = function(prop, oldVal, newVal)
  322. {
  323.    clearInterval(this.hScroller.synchScroll);
  324.    clearInterval(this.vScroller.synchScroll);
  325.    this.hScroller.synchScroll = setInterval(this.hScroller,"onTextChanged",50);
  326.    this.vScroller.synchScroll = setInterval(this.vScroller,"onTextChanged",50);
  327.    return newVal;
  328. };
  329. FScrollBarClass.prototype.onTextChanged = function()
  330. {
  331.    if(!this.enable || this.textField == undefined)
  332.    {
  333.       return undefined;
  334.    }
  335.    clearInterval(this.synchScroll);
  336.    if(this.horizontal)
  337.    {
  338.       var _loc3_ = this.textField.hscroll;
  339.       this.setScrollProperties(this.textField._width,0,this.textField.maxhscroll);
  340.       this.setScrollPosition(Math.min(_loc3_,this.textField.maxhscroll));
  341.    }
  342.    else
  343.    {
  344.       this.textField.scroll = 0;
  345.       _loc3_ = this.textField.scroll;
  346.       var _loc2_ = this.textField.bottomScroll - this.textField.scroll;
  347.       this.setScrollProperties(_loc2_,1,this.textField.maxscroll);
  348.       this.setScrollPosition(Math.min(_loc3_,this.textField.maxscroll));
  349.    }
  350. };
  351. FScrollBarClass.prototype.executeCallBack = function()
  352. {
  353.    if(this.textField == undefined)
  354.    {
  355.       super.executeCallBack();
  356.    }
  357.    else if(this.horizontal)
  358.    {
  359.       this.textField.hscroll = this.getScrollPosition();
  360.    }
  361.    else
  362.    {
  363.       this.textField.scroll = this.getScrollPosition();
  364.    }
  365. };
  366. FScrollBarClass.prototype.piss = function()
  367. {
  368.    trace("piss");
  369. };
  370. Object.registerClass("FScrollBarSymbol",FScrollBarClass);
  371.